<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>10.给我一个对象还你一个世界</title>
</head>

<body>
  <script>
    function User (name) {
      this.name = name;
    }
    User.prototype = {
      constructor: User,
      show () {
        console.log(this.name);
      }
    }
    let hd = new User('后盾人');
    console.log(hd);//User {name: '后盾人'}
    function createByObject (obj, ...args) {
      const constructor = Object.getPrototypeOf(obj).constructor;
      return new constructor(...args);
    }
    //创建出新的对象 ，向军
    let xj = createByObject(hd, '向军');
    console.log(xj);//User {name: '向军'}
    xj.show();//向军
  </script>
</body>

</html>